package com.android.personal.kotlin.greendao.helper;

import android.content.Context;

import com.android.personal.kotlin.greendao.DBManager;
import com.android.personal.kotlin.greendao.dao.DaoSession;
import com.android.personal.kotlin.greendao.dao.UserModelDao;
import com.android.personal.kotlin.greendao.model.UserModel;

import java.util.List;

/**
 * Created by zhangwentao on 2016/12/28.
 */

public class GDUserHelper {

    private volatile static GDUserHelper sGDUserHelper;

    private DaoSession mDaoSession;
    private UserModelDao mUserModelDao;

    private GDUserHelper() {}

    public static GDUserHelper getInstance(Context context) {
        if (sGDUserHelper == null) {
            synchronized (GDUserHelper.class) {
                if (sGDUserHelper == null) {
                    sGDUserHelper = new GDUserHelper();
                }
            }
        }
        sGDUserHelper.mDaoSession = DBManager.getInstance(context).getDaoSession();
        sGDUserHelper.mUserModelDao = sGDUserHelper.mDaoSession.getUserModelDao();
        return sGDUserHelper;
    }

    public void insertUser(UserModel user) {
        mUserModelDao.insert(user);
    }

    public List<UserModel> loadUserModel() {
        return mUserModelDao.loadAll();
    }

    public void deleteAll() {
        mUserModelDao.deleteAll();
    }
}
